<form action="channel.manage.php?action=update" id="form_add" name="form_add" method="post">
<input type="hidden" name="add_module_sign_num" id="add_module_sign_num" value="0" />
<input type="hidden" name="txtid" id="txtid" value="<tpl> $channel_array.channel_id </tpl>" />
<!-- 标识，主要用于区别首页管理和频道管理读取配置文件的区别，index为首页管理，channel为频道管理 -->
<input type="hidden" name="channel_read_param" id="channel_read_param" value="channel" />
<table border="0" cellpadding="0" cellspacing="0" class="from_table">
	<tr>
	  <th width="150"><tpl> $langChannelName </tpl></th>
	  <td valign="top" class="td rowform"><input name="txtname" type="text" id="txtname"  class="txtinput" maxlength="100" value="<tpl> $channel_array.channel_name </tpl>" /></td>
		<td align="left" class="vtop tips2"><tpl> $langChannelNameDescription </tpl><label style="display:none" for="txtname" class="wrong" metaDone="true" generated="true"></label></td>
	</tr>
	<tr>
	  <th width="150"><tpl> $langChannelCompositor </tpl></th>
	  <td valign="top" class="td rowform"><input name="txtsort" type="text" id="txtsort" class="txtinput" maxlength="100" value="<tpl> $channel_array.channel_sort </tpl>" /></td>
		<td align="left" class="vtop tips2"><tpl> $langChannelSortDescription </tpl><label style="display:none" for="txtsort" class="wrong" metaDone="true" generated="true"></label></td>
	</tr>
	<tr>
	  <th width="150"><tpl> $langChannelId </tpl></th>
	  <td valign="top" class="td rowform"><input name="txtsign" type="text" id="txtsign" class="txtinput" maxlength="100" value="<tpl> $channel_array.channel_sign </tpl>" /></td>
		<td align="left" class="vtop tips2"><tpl> $langChannelEnglishAndNum </tpl><label style="display:none" for="txtsign" class="wrong" metaDone="true" generated="true"></label></td>
	</tr>
	<tr>
	  <th width="150"><tpl> $langChannelEstate </tpl></th>
		<td colspan="2" align="left" class="td rowform"><input name="txtstate" type="radio" value="0" <tpl> if $channel_array.channel_state eq "0" </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langCOpen </tpl>
			<input name="txtstate" type="radio" value="1" <tpl> if $channel_array.channel_state eq "1" </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langCClose </tpl></td>
	</tr>
	<tr>
	  <th width="150"><tpl> $langChannelSelectTemplate </tpl></th>
		<td colspan="2" align="left" class="td rowform"><tpl> $path </tpl>
			<select name="channel_temp_name" id="channel_temp_name">
				<tpl> foreach item=one from=$file_array </tpl>
					<tpl> if $one.type eq "file" </tpl>
						<option <tpl> if $channel_array.channel_temp_name eq $one.name </tpl>selected="selected"<tpl> /if </tpl> value="<tpl> $one.name </tpl>"><tpl> $one.name </tpl></option>
					<tpl> /if </tpl>
				<tpl> /foreach </tpl>
			</select></td>
	</tr>
	<tr>
	  <th width="150"><tpl> $langChannelModule </tpl></th>
		<td class="td rowform" colspan="2">
			<table width="100%" border="0" cellpadding="0" cellspacing="0" rules="none" class="tables_table" >
				<!-- 已添加的模块列表 -->
				<tbody id="add_module_sign" align="left">
					<tpl> foreach from=$module_array item=one key=key </tpl>
						<tr>
							<td>
							<span class="btn_left">
								<input  type='button' value='<tpl> $key </tpl>' onclick="modi_module('<tpl> $key </tpl>');deleteRow(this);set_module_style('disabled');" class="btn_submit"/>
							  </span>
								<input type='hidden' name='<tpl> $key </tpl>'  id='<tpl> $key </tpl>' value='<tpl> $one </tpl>'/><a href="javascript:;" onclick="javascript: copyToClipboard('<tpl> $key </tpl>')" title="<tpl> $langChannelCopyModuleName </tpl>" class="copy_a_pic"></a>
								<a href='javascript:;' onclick='if($("#add_module")[0].disabled != true){deleteProhibitionElements("<tpl> $key </tpl>");deleteRow(this);}else{alert("<tpl> $langModuleDelWrong </tpl>");}' title="<tpl> $langChannelDelThisModule </tpl>" class="del_a_pic"></a>
						  </td>
						</tr>
					<tpl> /foreach </tpl>
				</tbody>
		  </table>		</td>
	</tr>
	<tr>
	  <th width="150"><tpl> $langChannelModule </tpl></th>
		<td colspan="2" align="left" class="td rowform">
		<span class="btn_left">
			<input type="button" value="<tpl> $langChannelAddModule </tpl>" id="add_module" class="btn_submit"/>
		  </span>
		  <tpl> $langChannelNewModuleName </tpl></td>
	</tr>

</table>
<div class="table-5-bottom">

<div class="btn_marginleft">
<span class="btn_left">
		<input type="submit" class="btn_submit" value="<tpl> $langChannelSubmit </tpl>" />
	  </span>
		<span class="btn_left">
		<input type="button" class="btn_submit" value="<tpl> $langChannelReturn </tpl>" onclick="ShowDiv='result_content';getPageContent('channel.manage.php?action=ajax_list');" />
	  </span>
    </div>
  </div>
</form>
<div id="module_block" style="display:none; cursor: default; padding:10px"></div> 
<script>
var module_block = $('#module_block')[0];//模块遮罩显示
$(document).ready(function() {

	//不准使用的隐藏域，文本域名,数组形式的
	Prohibition = new Array();
	Prohibition[0] = "add_module_sign_num";//新增模块区域的行数，也就是新增模块的个数
	Prohibition[1] = "txtname";//频道名称
	Prohibition[2] = "txtsort";//频道排序
	Prohibition[3] = "txtstate";//频道状态
	Prohibition[4] = "add_module";//新增模块按钮
	Prohibition[5] = "body_module";//模块添加区域
	Prohibition[6] = "add_module_sign";//已添加的模块列表区域
	Prohibition[7] = "channel_temp_name";//选择模板
	Prohibition[8] = "|||";//参数分隔符
	//把已有模块的模块标识符附给数组
	<tpl> foreach from=$module_array item=one key=key </tpl>
		var length = Prohibition.length;
		Prohibition[length] = "<tpl> $key </tpl>";
	<tpl> /foreach </tpl>
	//添加
	var options = {
		beforeSubmit:  function(){showLoading(showSaveText);},
		success:       function(msg){
							hideLoading();
							showMessage(msg.message,msg.type);
							if(msg.type == '1'){
								ST(0,0);
								ShowDiv	= 'result_content';
								getPageContent("channel.manage.php?action=ajax_list");
							}
						},
		type:      'post',
		dataType:  'json'
	};
	
	//对添加表单做的验证定义
	$("#form_add").validate({
		errorClass: "wrong",
		rules: {
			txtname: {required:true},
			txtsort: {required:true,number:true},
			txtsign: {required:true}
		},
		messages: {
			txtname: {required:"<tpl> $langChannelNameNotNull </tpl>"},
			txtsort: {required:"<tpl> $langChannelNumNotNull </tpl>",number:"<tpl> $langChannelNumIsNumber </tpl>"},
			txtsign: {required:"<tpl> $langChannelIdNotNull </tpl>"}
		},
		submitHandler: function() {
			$('#form_add').ajaxSubmit(options);
		}
	});
	
	//添加频道模块
	$('#add_module').click(function(e){
		$.blockUI(module_block, { width: '565px', height:'385px', top:'80px', left:'20%', padding:'10px' });//遮罩
		
		$('#module_block').html("<span style='font-size: 12px; font-weight:bold; color:#007DC6; textAlign:left'><tpl> $langChannelModule </tpl>：</span><tr><td align='left'><select name='body_select_module' id='body_select_module' onchange='change_module(this.value);ajax_get_module(this.value)'><option value='adv_module'><tpl> $langChannelAdv </tpl></option><option value='vote_module'><tpl> $langChannelVote </tpl></option><option value='product_module'><tpl> $langChannelMerchandise </tpl></option><option value='shop_module'><tpl> $langChannelShop </tpl></option><option value='pclass_module'><tpl> $langChannelMerchandiseType </tpl></option><option value='shopclass_module'><tpl> $langChannelShopType </tpl></option></select></td><td><input type='button' value='<tpl> $langChannelDel </tpl>' onclick='deleteRow(this);set_module_style(\"no_disabled\");' /></td><div id='adv_module' style='display:none'></div><div id='vote_module' style='display:none'></div><div id='product_module' style='display:none'></div><div id='shop_module' style='display:none'></div><div id='pclass_module' style='display:none'></div><div id='shopclass_module' style='display:none'></div></td></tr>");
		//禁止增加按钮
		$("#add_module").attr("disabled","disabled");
		//显示第一个值的页面
		change_module($("#body_select_module option:selected").val());
		//取模块页面
		ajax_get_module($("#body_select_module option:selected").val());
		//禁止已经存在的模块按钮
		set_module_style("disabled");
	});
});

//删除模块行
function deleteRow(elem) {

	//去除遮罩
	$.unblockUI();
	
	// 先抓到是哪一個 tr
	var row = $(elem).parent().parent();
	// 移除它
	row.fadeOut('normal', function() {
	row.remove();
	});
	//开放增加按钮
	$("#add_module").attr("disabled","");
}

//切换模块显示
function change_module(str){
	$('#adv_module').html('');
	$('#vote_module').html('');
	$('#product_module').html('');
	$('#shop_module').html('');
	$('#pclass_module').html('');
	$('#shopclass_module').html('');
	
	$('#'+str).slideDown("fast");//展开
}

//发送请求取模块页面
function ajax_get_module(str){
	$.ajax({
		url: "channel.manage.php",
		data: "action=get_module&module_name="+str,
		type:'post',
		dataType:"html",
		beforeSubmit:  showLoading(showText),   // 提交之前执行的方法
		success: function(msg){
			hideLoading();
			if(msg != ""){
				$("#"+str).html(msg);
			}else{
				$("#"+str).html("<tpl> $langChannelModuleNonentitySelectOther </tpl>");
			}
		}
	});
	return false;
}

//修改模块信息
function modi_module(str){
	
	var temp_name = '';//模块标识符
	
	temp_name_array = str.split("_");//切 标识符名称，'_'分割
	
	var module_name=temp_name_array[0]+'_'+temp_name_array[1];//服务器端程序判断模块名
	
	$.ajax({
		url: "channel.manage.php",
		data: "action=get_module&module_name="+module_name+"&modi_string="+$('#'+str).val(),
		type:'post',
		dataType:"html",
		beforeSubmit:  showLoading(showText),// 提交之前执行的方法
		success: function(msg){
			$.blockUI(module_block, {width: '565px', height:'385px',top:'80px', left:'20%', padding:'10px' });//遮罩
		
			deleteProhibitionElements(str);//移除在Prohibition该模块名称
			
			$("#add_module").attr("disabled","disabled");//禁止模块添加按钮
			
			hideLoading();
			
			$('#module_block').html("<span style='font-size: 12px;textAlign:left '><tpl> $langChannelModule </tpl>：</span><tr><td><div id='"+module_name+"' style='display:none'></div></td></tr>");
			
			change_module(module_name); //显示该模块所在的层
			
			$("#"+module_name).html(msg); //填充修改信息
		}
	});
	return false;
}


//对于新增模板名称的验证，是否已经重复，如果重复则返回false，如果没有重复则 写入数组Prohibition
function checkRepeatModuleName(name){
	for(index in Prohibition) {
		if(Prohibition[index] == name){
			alert("<tpl> $langChannelModuleIdSelectOtherName </tpl>");
			return false;
		}
	}
	//把新值写入数组Prohibition
	Prohibition[Prohibition.length] = name;	
	return true;
}

//删除Prohibition的元素
function deleteProhibitionElements(elem){//elem为需要删除的元素名
	for(index in Prohibition) {
		if(Prohibition[index] == elem){
			delete Prohibition[index];
			return true;
		}
	}
	return false;
}

//add_module_sign
//当编辑时候将模块按钮设置为不可用
function set_module_style(str){
	if(str=='disabled'){
		$("#add_module_sign input[@type=button]").each(function(){
			$(this).attr('disabled',true);
		})
	}else if(str='no_disabled'){
		$("#add_module_sign input[@type=button]").each(function(){
			$(this).attr('disabled','');
		})
	}
	return false;
}


//计算有多少列信息
function numRow(){
	var num = $('#add_module_sign').children('tr').length;
	$('#add_module_sign_num').val(num);
	alert(num);
}
// js 复制功能 支持 for IE/FireFox/mozilla/ns 
function copyToClipboard(txt){ 
	
     if(window.clipboardData){ 
     	
             window.clipboardData.clearData(); 
             window.clipboardData.setData("Text", txt); 
             
     }else if(navigator.userAgent.indexOf("Opera") != -1){ 
     	
          window.location = txt; 
          
     }else if (window.netscape){ 
     	
          try{
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
          }catch(e){ 
               alert("<tpl> $errChannelBrowseWrong </tpl>"); 
          }
          
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 
          
          if (!clip) {return;}
               
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); 
          
          if (!trans) {return;}
          
          trans.addDataFlavor('text/unicode'); 
          
          var str = new Object(); 
          var len = new Object(); 
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 
          var copytext = txt; 
          str.data = copytext; 
          trans.setTransferData("text/unicode",str,copytext.length*2); 
          var clipid = Components.interfaces.nsIClipboard; 
          
          if (!clip){return false;}
          clip.setData(trans,null,clipid.kGlobalClipboard); 
     }
}
</script>